<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
include 'operations/connection.php';
$query="select sa_allowance_hard_holiday.sub_salary_day,sa_allowance_hard_holiday.id,sa_allowance_hard_holiday.allowance_hard,sa_allowance_hard_holiday.allowance_holiday,sa_allowance_hard_holiday.is_all_dayoff,sa_allowance_hard_holiday.is_half_dayoff,sa_allowance_hard_holiday.is_late,sa_allowance_hard_holiday.is_status from sa_allowance_hard_holiday ORDER BY sa_allowance_hard_holiday.is_status desc";
$m_query=mysql_query($query);

$_REQUEST['sub_salary_day']=0;
$_REQUEST['is_late']=0;
$_REQUEST['is_half_dayoff']=0;
$_REQUEST['is_all_dayoff']=0;
$_REQUEST["abc"]="0";
$_REQUEST['first_create']=date("Y-m-d");
$_REQUEST['user_create']=$_SESSION['fullname'];
$_REQUEST['user_last_update']='';
$_REQUEST['time_last_update']='';
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	document.getElementById("is_late").focus();
	document.getElementById("is_late").select();
	$('#allowance_holiday').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
	$('#allowance_hard').priceFormat({
		prefix: '',
		centsLimit: 0,
		centsSeparator: '',
		thousandsSeparator: ','
	});
});

function noloveyou(){
	$(document).ready(function(){
		$('#allowance_holiday').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
		$('#allowance_hard').priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
	});
}

function enterTable(e,value){
    var key = window.event ? e.keyCode : e.which;
    if (key == 13 || key == 8 || key == 46  || key == 37 || key == 39 ) {
    	if(key==13){
    		var j = 0;
    		var listID = new Array();
    		listID = listID.concat(["is_late","is_half_dayoff","is_all_dayoff","allowance_hard","sub_salary_day","allowance_holiday","abc"]);	
    		for (j = 0; j < listID.length; j++){	
    			if (listID[j] == value) {	
    				if (j == listID.length - 1) {
    					return false;
    				}
    				document.getElementById(listID[j + 1]).focus();
    				document.getElementById(listID[j + 1]).select();
    				return false; 
    			}
    		}
    		
    		return false;
    	}else
    		return true;	
    }else if ( key < 48 || key > 57 ) {
        return false;
    }
    else return true;			
}

function checkonly(tenid,field){
	if(document.getElementById(tenid).checked == true){
		for(var i = 0;i<field.length;i++)
	    {
			field[i].checked = false ;
	    }
		document.getElementById(tenid).checked = true;
	 	var gtid=document.getElementById(tenid).value;
	 	document.getElementById("hanhdong").value="updel";
		document.getElementById("idgen").value=gtid;
		if(document.getElementById("idgen").value!="null"){
			var iddel=document.getElementById("idgen").value;
			if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		 		xmlhttp=new XMLHttpRequest();
		 	}else{// code for IE6, IE5
		 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		 	}
		 	xmlhttp.onreadystatechange=function(){
				 	if (xmlhttp.readyState==4 && xmlhttp.status==200){
				 		document.getElementById("showinput").innerHTML=xmlhttp.responseText;
				 		noloveyou();
				 	}
			 	}
		 	xmlhttp.open("POST","ajax/salary/sa_viewcheck_allowance_hard_holiday.php?idgen="+gtid,true);
		 	xmlhttp.send();
		}
	}else{
		document.getElementById(tenid).checked=false;
		resetvalue();
	}
	
 }

function add(user){
	var islate=document.getElementById("is_late").value;
	var ishalfdayoff=document.getElementById("is_half_dayoff").value;
	var aholiday=document.getElementById("allowance_holiday").value;
	var isalldayoff=document.getElementById("is_all_dayoff").value;
	var ahard=document.getElementById("allowance_hard").value;
	var astatus=$('input[name=abc]:checked').val();
	var subsalaryday=document.getElementById("sub_salary_day").value;
		
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
 		xmlhttp=new XMLHttpRequest();
 	}else{// code for IE6, IE5
 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 	}
 	xmlhttp.onreadystatechange=function(){
		 	if (xmlhttp.readyState==4 && xmlhttp.status==200){
		 		document.getElementById("showdata").innerHTML=xmlhttp.responseText;
		 		var loi=document.getElementById("viewloi").value;
		 		if(loi!=""){
			 		if(loi=="<?php echo $l_themthanhcong;?>"){
				 		alert(loi);
				 		resetvalue();
			 		}else{
			 			alert(loi);
			 			noloveyou();
			 		}
		 		}
		 	}
	 	}
 	xmlhttp.open("POST","ajax/salary/sa_add_allowance_hard_holiday.php?hanhdong=add&islate="+islate+"&ishalfdayoff="+ishalfdayoff+"&aholiday="+aholiday+"&isalldayoff="+isalldayoff+"&ahard="+ahard+"&astatus="+astatus+"&subsalaryday="+subsalaryday,true);
 	xmlhttp.send();
}

function checknulldata(){
	var islate=document.getElementById("is_late").value;
	var ishalfdayoff=document.getElementById("is_half_dayoff").value;
	var aholiday=document.getElementById("allowance_holiday").value;
	var isalldayoff=document.getElementById("is_all_dayoff").value;
	var ahard=document.getElementById("allowance_hard").value;
	var subsalaryday=document.getElementById("sub_salary_day").value;

	if(islate=="" || islate<0){
		alert("(*)not null and >0");
		return false;
	}else if(ishalfdayoff=="" || ishalfdayoff<0){
		alert("(*)not null and >0");
		return false;
	}else if(aholiday=="" || aholiday<0){
		alert("(*)not null and >0");
		return false;
	}else if(isalldayoff=="" || isalldayoff<0){
		alert("(*)not null and >0");
		return false;
	}else if(ahard=="" || ahard<0){
		alert("(*)not null and >0");
		return false;
	}else if(subsalaryday=="" || subsalaryday<0){
		alert("(*)not null and >0");
		return false;
	}else{
		return true;
	}
}

function thucthi_add(user){
	if(document.getElementById("hanhdong").value=="addnew"){
		if(checknulldata()==true){
			add(user);
		}
	}
}

function thucthi_update(user){
	if(document.getElementById("hanhdong").value=="updel"){
		if(checknulldata()==true){
			update();
		}
	}
}

function thucthi_delete(){
	if(document.getElementById("hanhdong").value=="updel"){
		if(document.getElementById("idgen").value!="null"){
			var iddel=document.getElementById("idgen").value;
			hoi= confirm("<?php echo $l_areyousure;?>");
			if (hoi==true) {
				if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			 		xmlhttp=new XMLHttpRequest();
			 	}else{// code for IE6, IE5
			 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			 	}
			 	xmlhttp.onreadystatechange=function(){
					 	if (xmlhttp.readyState==4 && xmlhttp.status==200){
					 		document.getElementById("showdata").innerHTML=xmlhttp.responseText;
					 		var loi=document.getElementById("viewloi").value;
					 		if(loi!=""){
						 		if(loi=="<?php echo $l_xoathanhcong;?>"){
							 		alert(loi);
							 		resetvalue();
						 		}else{
						 			for(var i = 0;i<document.nsa_f_allowance_hard_holiday.list.length;i++)
								    {
									    if(document.nsa_f_allowance_hard_holiday.list[i].value==iddel)
									    	document.nsa_f_allowance_hard_holiday.list[i].checked = true ;
									    else
											document.nsa_f_allowance_hard_holiday.list[i].checked = false ;
								    }
						 			alert(loi);
						 			noloveyou();
						 		}
					 		}
					 	}				 	}
			 	xmlhttp.open("POST","ajax/salary/sa_add_allowance_hard_holiday.php?hanhdong=del&idgen="+iddel,true);
			 	xmlhttp.send();
			}
		}
	}
}

function update(){
	var id=document.getElementById("idgen").value;
	if(id!="null"){
		hoi= confirm("<?php echo $l_areyousure;?>");
		if (hoi==true) {
			var islate=document.getElementById("is_late").value;
			var ishalfdayoff=document.getElementById("is_half_dayoff").value;
			var aholiday=document.getElementById("allowance_holiday").value;
			var isalldayoff=document.getElementById("is_all_dayoff").value;
			var ahard=document.getElementById("allowance_hard").value;
			var astatus=$('input[name=abc]:checked').val();
			var subsalaryday=document.getElementById("sub_salary_day").value;

			if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		 		xmlhttp=new XMLHttpRequest();
		 	}else{// code for IE6, IE5
		 		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		 	}
		 	xmlhttp.onreadystatechange=function(){
				 	if (xmlhttp.readyState==4 && xmlhttp.status==200){
				 		document.getElementById("showdata").innerHTML=xmlhttp.responseText;
				 		//resetvalue();
				 		for(var i = 0;i<document.nsa_f_allowance_hard_holiday.list.length;i++)
					    {
						    if(document.nsa_f_allowance_hard_holiday.list[i].value==id)
						    	document.nsa_f_allowance_hard_holiday.list[i].checked = true ;
						    else
								document.nsa_f_allowance_hard_holiday.list[i].checked = false ;
					    }
				 		var loi=document.getElementById("viewloi").value;
				 		if(loi!=""){
				 			alert(loi);
				 			resetvalue();
				 		}
				 	}
			 	}
		 	xmlhttp.open("POST","ajax/salary/sa_add_allowance_hard_holiday.php?hanhdong=update&idgen="+id+"&islate="+islate+"&ishalfdayoff="+ishalfdayoff+"&aholiday="+aholiday+"&isalldayoff="+isalldayoff+"&ahard="+ahard+"&astatus="+astatus+"&subsalaryday="+subsalaryday,true);
		 	xmlhttp.send();
		}
	}
}

function resetvalue(){
	document.getElementById("is_late").value=0;
	document.getElementById("is_half_dayoff").value=0;
	document.getElementById("allowance_holiday").value=0;
	document.getElementById("is_all_dayoff").value=0;
	document.getElementById("allowance_hard").value=0;
	document.getElementById("sub_salary_day").value=0;
	document.getElementById("user_create").value=document.getElementById("userCreate").value;
	document.getElementById("user_last_update").value="";
	document.getElementById("time_last_update").value="";
	document.getElementById("first_create").value="<?php echo date("Y-m-d");?>";
	document.getElementById("hanhdong").value="addnew";
	document.getElementById("idgen").value="null";
	document.getElementById("is_late").focus();
	document.getElementById("is_late").select();

	for (var i=0; i < document.nsa_f_allowance_hard_holiday.abc.length; i++)
	{
	   if (document.nsa_f_allowance_hard_holiday.abc[i].value=="0")
	   {
	       document.nsa_f_allowance_hard_holiday.abc[i].checked=true;
	   }else{
		   document.nsa_f_allowance_hard_holiday.abc[i].checked=false;
	   }
	}
	for(var i = 0;i<document.nsa_f_allowance_hard_holiday.list.length;i++)
    {
		document.nsa_f_allowance_hard_holiday.list[i].checked = false ;
    }
	noloveyou();
}

</script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<form id="sa_f_allowance_hard_holiday" name="nsa_f_allowance_hard_holiday" method="post" action="">
<div id="contains">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant;?> &rarr; <?php echo $l_ml_tinh_luong;?> &rarr; <?php echo $l_setup_regulation;?> &rarr; <?php echo $l_allowance_hard_holiday;?></div>
	<div class="content_code">
		<div class="approval-right">
			<div style="width:100%" id="showdata">
				<table class="cssTable" border="1" style="width:100%">
					<thead>
						<tr>
							<th scope="col" style="width:10px"></th>
							<th scope="col" style="height:45px;"><?php echo $l_late;?></th>
							<th scope="col"><?php echo $l_half_dayoff;?></th>
							<th scope="col"><?php echo $l_all_dayoff;?></th>
							<th scope="col"><?php echo $l_allowance_hard;?></th>
							<th scope="col"><?php echo $l_sub_salary_day;?></th>
							<th scope="col"><?php echo $l_allowance_holiday;?></th>
							<th scope="col"><?php echo $l_Activestatus;?></th>
						</tr>
					</thead>
					<tbody>
						<?php 
							if(mysql_num_rows($m_query)>0){
								$i=0;
								while($row=mysql_fetch_array($m_query)){
								
									if($row['is_status']==1){
										?>
									<tr style="color:green;">
										<?php 
									}else{
									?>
									<tr>
									<?php }?>
									<td style="width: 10px"><div style="text-align:center"><input onclick="checkonly(this.id,document.nsa_f_allowance_hard_holiday.list);" type="checkbox" name="list" id="<?php echo 'checkcus'.$i?>" value="<?=$row['id']?>"/></div></td>
									<td ><?php echo $row['is_late']."(".$l_lan.")";?></td>
									<td ><?php echo $row['is_half_dayoff']."(".$l_lan.")";?></td>
									<td ><?php echo $row['is_all_dayoff']."(".$l_lan.")";?></td>
									<td ><?php echo number_format($row['allowance_hard']);?></td>
									<td ><?php echo $row['sub_salary_day']."(".$l_ngay.")";?></td>
									<td ><?php echo number_format($row['allowance_holiday']);?></td>
									<td >
										<?php 
											if($row['is_status']==1){
												echo $l_active;
											}else{
												echo $l_status_saved;
											}
										?>
									</td>
									</tr>
								<?php 
									$i++;
								}
							}
						?>
					</tbody>
				</table>
			</div>
			<div style="margin: 10px 7px 5px 3px; color: #508E21; border-bottom: 1px dotted silver"> <?php echo $l_allowance_hard_holiday;?> </div>
			<div id="showinput" style="width:100%">
				<table style="border-bottom: 1px dotted silver; padding:10px 5px" width="100%">
					<tr>
						<td class="tdfirst" ><?php echo $l_late;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
						<td><input type="text" value="<?=$_REQUEST['is_late']?>" onkeypress="return enterTable(event,this.id);"  name="is_late" id="is_late"  class="in_testfield" style="width:516px" /><span style="padding-left:5px"><?php echo "(".$l_lan.")"?></span></td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_half_dayoff;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
					<td><input type="text" value="<?=$_REQUEST['is_half_dayoff']?>" onkeypress="return enterTable(event,this.id);" name="is_half_dayoff" id="is_half_dayoff" class="in_testfield" style="width:516px" /><span style="padding-left:5px"><?php echo "(".$l_lan.")"?></span></td>
					</tr> 
					<tr>
						<td class="tdfirst"><?php echo $l_all_dayoff;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
						<td><input type="text" value="<?=$_REQUEST['is_all_dayoff']?>" onkeypress="return enterTable(event,this.id);" name="is_all_dayoff" id="is_all_dayoff"  class="in_testfield" style="width:516px" /><span style="padding-left:5px"><?php echo "(".$l_lan.")"?></span></td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_allowance_hard;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
					<td><input type="text" value="<?=number_format($_REQUEST['allowance_hard'])?>" onkeypress="return enterTable(event,this.id);" id="allowance_hard" name="allowance_hard" class="in_testfield" style="width:516px" /> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_sub_salary_day;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
					<td><input type="text" value="<?=$_REQUEST['sub_salary_day']?>" onkeypress="return enterTable(event,this.id);" id="sub_salary_day" name="sub_salary_day" class="in_testfield" style="width:516px" /><span style="padding-left:5px"><?php echo "(".$l_ngay.")"?></span> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_allowance_holiday;?>:<span style="color:red;font-weight: bold;float:right;">(*)</span></td>
					<td><input type="text" value="<?=number_format($_REQUEST['allowance_holiday'])?>" onkeypress="return enterTable(event,this.id);" id="allowance_holiday" name="allowance_holiday" class="in_testfield" style="width:516px" /> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_Activestatus;?>:</td>
					<td>
						<input type="radio"  id="abc" name="abc" value="1" <?php if ($_REQUEST["abc"]=="1") echo "checked";?> /> <?php echo $l_apdung;?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="radio" name="abc" id="abc"  value="0" <?php if ($_REQUEST["abc"]=="0") echo "checked";?>/> <?php echo $l_status_saved;?>
					</td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_user_create;?>:</td>
					<td><input type="text" value="<?php echo $_REQUEST['user_create'];?>" onkeypress="return enterTable(event,this.id);" id="user_create" name="user_create" class="in_testfield" style="width:516px;background: #d7d9dd;"  readonly="readonly" /> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_first_create;?>:</td>
					<td><input type="text" value="<?php echo $_REQUEST['first_create'];?>" onkeypress="return enterTable(event,this.id);" id="first_create" name="first_create" class="in_testfield" style="width:516px;background: #d7d9dd;"  readonly="readonly" /> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_user_last_update;?>:</td>
					<td><input type="text" onkeypress="return enterTable(event,this.id);" id="user_last_update" name="user_last_update" class="in_testfield" style="width:516px;background: #d7d9dd;" readonly="readonly" /> </td>
					</tr>
					<tr>
					<td class="tdfirst"><?php echo $l_time_last_update;?>:</td>
					<td><input type="text" onkeypress="return enterTable(event,this.id);" id="time_last_update" name="time_last_update" class="in_testfield" style="width:516px;background: #d7d9dd;" readonly="readonly" /> </td>
					</tr>
				</table>
			</div>
			
			<div>
				<input type="hidden" name="content" id="content" value="allowance_hard_holiday" />
				<input type="hidden" name="userCreate" id="userCreate" value="<?=$_SESSION['fullname']?>" />
				<input type="hidden" name="hanhdong" id="hanhdong" value="addnew" />
				<input type="hidden" name="idgen" id="idgen" value="null" />
			</div>
			<table style="border-bottom: 1px dotted silver; padding:10px 5px" width="100%">
				<tr>
					<td class="tdfirst" style="background: none;"></td>
					<td style="padding-left: 45px">
						<input onclick="thucthi_add('<?php echo $_SESSION['IDEmployee'];?>');" id="AddNew" name="AddNew" style="margin-right:3px" type="button" value="<?php echo $l_add;?>" class="btnupbg btnupload" />
						<input onclick="thucthi_update('<?php echo $_SESSION['IDEmployee'];?>');" id="Update" name="Update" style="margin-right:3px" type="button" value="<?php echo $l_update;?>" class="btnupbg btnupload" />
						<input onclick="thucthi_delete();" id="Delete" name="Delete" style="margin-right:3px" type="button" value="<?php echo $l_delete;?>" class="btnupbg btnupload" />
						<input onclick="resetvalue();" id="Reset" name="Reset" style="margin-right:3px" type="button" value="<?php echo $l_reset;?>" class="btnupbg btnupload" />
					</td>
				</tr>
			</table>
		</div>
	</div>
</div>
</form>